import Vue from 'vue'
import App from './App.vue'
import store from './store'
import router from './router'
import './plugins/element.js'

Vue.config.productionTip = false

// axios
import axios from 'axios'
//全局封装axios请求
Vue.prototype.$axios = axios

//公共路径
global.url_g = '/api'

// 导航卫士
router.beforeEach((to, from, next) => {
  // 登出操作
  if (to.path === '/' && sessionStorage.getItem('token') && from.path !== '/index'){
    sessionStorage.removeItem('token')
    next({
      path: '/'
    })
  }
  // token 失效  且不从login页进入
  else if (to.path !== '/' && !sessionStorage.getItem('token')){
    next({
      path: '/'
    })
  }
  // 已登录
  // else if (to.path !== '/' && sessionStorage.getItem('token')){
  //   next()
  // }
  next()
})

new Vue({
  store,
  router,
  render: h => h(App)
}).$mount('#app')
